#include "sprite.h"

Sprite::Sprite(SDL_Surface* screen, const char* filename) 
{
	m_screen = screen;

	printf("loading filename:[%s]\n", filename);
	m_sprite = SDL_LoadBMP(filename);

	if(m_sprite == NULL) {
		printf("Can't load %s\n", filename);
	}

	SDL_Surface* temp = NULL;
	if((temp = SDL_DisplayFormat(m_sprite)) == NULL) {
		printf("Couldn't convert %s to display format", filename);
	}
	SDL_FreeSurface(m_sprite);

	m_sprite = temp;

	printf("done loading filename %s\n", filename);

	//set blitRect attribute
	//only w and h is set since x and y is dynamic
	m_blitRect.w = m_sprite->w;
	m_blitRect.h = m_sprite->h;

}

void Sprite::draw(int x, int y)
{
	m_blitRect.x = x;
	m_blitRect.y = y;

	SDL_FillRect(m_screen, NULL, SDL_MapRGB( m_screen->format,0,0,0)); 

	SDL_BlitSurface(m_sprite, NULL, m_screen, &m_blitRect);

	
}

Sprite::~Sprite()
{
	delete m_sprite;
}

